package com.atguigu.gmall.user.controller;

import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.result.Result;
import com.atguigu.gmall.user.service.UserService;
import com.atguigu.gmall.util.AuthContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserApiController {
    @Autowired
    private UserService userService;

    /**
     * 查询用户地址列表（移动端），auth需要登录
     * /api/user/userAddress/auth/findUserAddressList/{userId}
     * @param request
     * @return
     */
    @GetMapping("/userAddress/auth/findUserAddressList")
    public Result findUserAddressList(HttpServletRequest request) {
        String userId = AuthContextHolder.getUserId(request);
        List<UserAddress> userAddressList = this.userService.findUserAddressListByUserId(Long.parseLong(userId));
        return Result.ok(userAddressList);
    }

    /**
     * 查询用户地址列表
     * /api/user/inner/findUserAddressListByUserId/{userId}
     * @param userId
     * @return
     */
    @GetMapping("/inner/findUserAddressListByUserId/{userId}")
    public List<UserAddress> findUserAddressListByUserId(@PathVariable Long userId) {
        List<UserAddress> userAddressList = this.userService.findUserAddressListByUserId(userId);
        return userAddressList;
    }
}
